<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of thanhvien_diachi_model
 *
 * @author Bui
 */
class Thanhvien_diachi_model extends CI_Model {

    //put your code here
    public function __construct() {
        parent::__construct();
    }

    function id_exists($id) {
        $this->db->where('thanhvien_id', $id);
        $query = $this->db->get('gs7s_thanhvien_diachi');
       
        if ($query->num_rows() > 0) {
            return true;
        } else {
            return false;
        }
        
         
        
    }

    function add_diachi($id) {
        $data = array(
            'tinhthanh' => $this->input->post('tinhthanh'),
            'quanhuyen' => $this->input->post('quanhuyen'),
            'xaphuong' => $this->input->post('xaphuong'),
            'diachi' => $this->input->post('nhaduong'),
        );
        $this->db->set('thanhvien_id', $id);
        $this->db->insert('gs7s_thanhvien_diachi', $data);
    }

    function update_diachi($id) {
        $data = array(
            'tinhthanh' => $this->input->post('tinhthanh'),
            'quanhuyen' => $this->input->post('quanhuyen'),
            'xaphuong' => $this->input->post('xaphuong'),
            'diachi' => $this->input->post('nhaduong'),
        );
        $this->db->where('thanhvien_id', $id);
        $this->db->update('gs7s_thanhvien_diachi', $data);
    }
    
    function get_diachi($id) {
        $this->db->where('thanhvien_id', $id);
        $query = $this->db->get('gs7s_thanhvien_diachi');
        //$query  = $query->result_array();
        //print_r($query->num_rows());
        //echo $query['0']['tinhthanh'];
        //if ($query->num_rows() > 0)
        
        if ($query->num_rows() != 0)
        {
            $query  = $query->result_array();
            return $query[0];
        }
    }
    
   
}

?>
